package com.fenghongzhang.day004;

import androidx.appcompat.app.AppCompatActivity;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

public class MainActivity extends AppCompatActivity {
    private StandardGSYVideoPlayer gsy;

    OrientationUtils orientationUtils;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        gsy = (StandardGSYVideoPlayer) findViewById(R.id.gsy);
//        gsy.onVideoPause();
        gsy.setUp(TestVideoUrl.videoUrls[2],true,"美女");

        //增加封面
        ImageView imageView = new ImageView(this);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageResource(R.mipmap.ic_launcher);
        gsy.setThumbImageView(imageView);

        //增加title
        gsy.getTitleTextView().setVisibility(View.INVISIBLE);
        //设置返回键
        gsy.getBackButton().setVisibility(View.VISIBLE);

        //设置旋转
          orientationUtils = new OrientationUtils(this, gsy);

        gsy.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                orientationUtils.resolveByClick();
                gsy.startWindowFullscreen(MainActivity.this,true,true);
            }
        });

        //是否可以滑动调整
        gsy.setIsTouchWiget(true);

        //设置返回按键功能
        gsy.getBackButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });


        gsy.startPlayLogic();
    }

    @Override
    protected void onPause() {
        super.onPause();
        GSYVideoManager.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        GSYVideoManager.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        GSYVideoManager.releaseAllVideos();
    }

    @Override
    public void onBackPressed() {
        //先返回正常状态
        if (orientationUtils.getScreenType() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            gsy.getFullscreenButton().performClick();
            return;
        }
        //释放所有
        gsy.setVideoAllCallBack(null);
        super.onBackPressed();
    }
}
